package Assignment;

import java.util.Random;
import java.util.Scanner;

//生成验证码
public class Test2 {
    public static void main(String[] args) {
        char[] arr = new char[62];
        for (int i = 0; i < arr.length; i++) {
            if (i<26){
                arr[i] = (char) ('A'+i);
            }else if (i<52){
                arr[i] = (char) ('a'+i-26);
            }else {
                arr[i] = (char)('0'+i-52);
            }
        }

        StringBuilder sb = new StringBuilder();
        Random random = new Random();
        for (int i = 0; i <4 ; i++) {
            sb.append(arr[random.nextInt(52)]);
        }

        sb.append(arr[random.nextInt(10)+52]);
        //数字打乱位置
        int index = random.nextInt(sb.length());
        char temp = sb.charAt(sb.length()-1);
        sb.setCharAt(sb.length()-1,sb.charAt(index));  //把随机索引上的值丢给最后一个
        sb.setCharAt(index,temp); //将最后的值丢给随即索引

        System.out.println(sb.toString());

    }
}
